﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;

namespace IconEditorXBAP.IconElements
{
    
    /// <summary>
    /// Interaction logic for BasicShape.xaml
    /// </summary>
    public partial class BasicShape : UserControl
    {
        protected Point mousePosition;
        protected bool isMouseCaptured;

        public BasicShape()
        {
            InitializeComponent();
            HideControls();

            this.MouseEnter += new MouseEventHandler(BasicShape_MouseEnter);
            this.MouseLeave += new MouseEventHandler(BasicShape_MouseLeave);
        }

        protected void BasicShape_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            FrameworkElement item = sender as FrameworkElement;
            mousePosition = e.GetPosition(null);
            isMouseCaptured = true;
            item.CaptureMouse();
            //item.Cursor = Cursors.Hand;
        }

        protected void BasicShape_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            FrameworkElement item = sender as FrameworkElement;
            mousePosition.X = mousePosition.Y = 0;
            isMouseCaptured = false;
            item.ReleaseMouseCapture();
            //item.Cursor = null;
        }


        protected virtual void ResizeThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {           
        }

        protected virtual void BasicShape_MouseMove(object sender, MouseEventArgs e)
        {
        }

        protected void BasicShape_MouseEnter(object sender, MouseEventArgs e)
        {
            ShowControls();
        }

        protected void BasicShape_MouseLeave(object sender, MouseEventArgs e)
        {
            HideControls();
        }

        protected void ShowControls()
        {
            LeftBorder.Opacity = 0.4;
            RightBorder.Opacity = 0.4;
            TopBorder.Opacity = 0.4;
            BottomBorder.Opacity = 0.4;

            LeftTopBorder.Opacity = 0.4;
            RightTopBorder.Opacity = 0.4;
            LeftBottomBorder.Opacity = 0.4;
            RightBottomBorder.Opacity = 0.4;
        }

        protected void HideControls()
        {
            LeftBorder.Opacity = 0.0;
            RightBorder.Opacity = 0.0;
            TopBorder.Opacity = 0.0;
            BottomBorder.Opacity = 0.0;

            LeftTopBorder.Opacity = 0.0;
            RightTopBorder.Opacity = 0.0;
            LeftBottomBorder.Opacity = 0.0;
            RightBottomBorder.Opacity = 0.0;
        }

        internal virtual string GetAnnotation()
        {
            return "";
        }
    }
}
